--POUR CONTROLE


define erp='erp_mli2.';
define outils='outils_mli2.';

--CREATE TABLE se_CPT_TPFTIERS AS (SELECT * FROM &erp.CPT_TPFTIERS WHERE 1=2);




DELETE FROM se_CPT_TPFTIERS;

 INSERT INTO se_CPT_TPFTIERS
 (SELECT id tpfTIERS_cod,
         0 enreg_id,
         'N' enreg_s,
         libelle tpfTIERS_lib,
         NULL tpfTIERS_lib2,
         'T' tiers_typ
    FROM uv_ctpf) ;



 UPDATE se_CPT_TPFTIERS tf SET enreg_id=(select enreg_id FROM &erp.CPT_TPFTIERS f WHERE f.tpfTIERS_cod=tf.tpfTIERS_cod) ;
 UPDATE se_CPT_TPFTIERS tf SET enreg_id=&outils.enreg_id.NEXtvaL WHERE enreg_id IS NULL OR enreg_id =0;



 CALL uvse_synchroverserp('tpfTIERS_cod','CPT_TPFTIERS','O') ;

 commit;



select * from (
SELECT &outils.stragg(source) source, tpfTIERS_cod, enreg_id, enreg_s, tpfTIERS_lib, tpfTIERS_lib2, tiers_typ
FROM (
  SELECT 'uv' source ,g.* FROM se_CPT_TPFTIERS g
  UNION ALL
  SELECT 'se' source ,g.* FROM &erp.CPT_TPFTIERS g
  )
GROUP BY  tpfTIERS_cod, enreg_id, enreg_s, tpfTIERS_lib, tpfTIERS_lib2, tiers_typ
HAVING Count(1)!=2) r
ORDER BY tpfTIERS_cod;